package com.lanou3g.ptp.api.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lanou3g.ptp.entity.Approval;
import com.lanou3g.ptp.service.ApprovalService;
import com.lanou3g.utils.PtpResult;
import com.lanou3g.utils.PtpResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;


@Api(description = "请假审核")
@RestController
public class ApprovalController {

    @Reference
    private ApprovalService approvalService;

    @ApiOperation("app学生请假申请接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "学生token"),
            @ApiImplicitParam(name = "type",value = "请假类型(1:事假  2:病假  3:其他)"),
            @ApiImplicitParam(name = "approval",value = "请假文本"),
            @ApiImplicitParam(name = "photo",value = "请假申请照片"),
            @ApiImplicitParam(name = "start",value = "请假开始时间"),
            @ApiImplicitParam(name = "over",value = "请假结束时间")
    })
    @PostMapping("/leave")
    private PtpResult studentApproval(String token,int type, String approval,String photo,Date start, Date over){
        Boolean aBoolean = approvalService.studentApproval(token,type,approval, photo,start, over);
        return PtpResultUtils.ok(aBoolean);
    }


    @ApiOperation("学生查询请假信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "学生token")
    })
    @GetMapping("/leaves")
    private PtpResult studentApproval(String token){
        Approval approval = approvalService.findApproval(token);
        return PtpResultUtils.ok(approval);
    }

    @ApiOperation("显示所有请假信息接口")
    @ApiImplicitParams({
    })
    @GetMapping("/approvals")
    private PtpResult approvalAll(){
        List<Approval> list = approvalService.approvalAll();
        return PtpResultUtils.ok(list);
    }

    @ApiOperation("老师审核批准")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token" ,value = "教师token"),
            @ApiImplicitParam(name = "id" ,value = "任务id"),
            @ApiImplicitParam(name = "i" ,value = "老师判定条件  <0同意 1拒绝>")
    })

    @GetMapping("/approval/{id}")
    private PtpResult teacherApproval(String token, @PathVariable Long id, Long i){
        Boolean aBoolean = approvalService.teacherApproval(token, id, i);
        return PtpResultUtils.ok(aBoolean);
    }
}
